package com.zfl;

public class MaxDepth {

    private int maxDepth;
    private int currentDepth;


    public int maxDepth(TreeNode root) {

        dfs(root);
        return this.maxDepth;

    }

    private void dfs(TreeNode root) {
        if (root==null)  {
            return;
        }
        this.currentDepth++;
        this.maxDepth = Math.max(this.currentDepth,this.maxDepth);
        dfs(root.left);
        dfs(root.right);
        this.currentDepth--;
    }
}
